import org.apache.avalon.fortress.util.dag.Vertex
import org.apache.avalon.fortress.util.dag.DirectedAcyclicGraphVerifier as DAG
import org.apache.avalon.fortress.util.dag.CyclicDependencyException

class VertexTests extends GroovyTestCase {


	void testSimpleDAG() {
		def root = new Vertex("A")
		def rootChild1 = new Vertex("B")
		def child1Child1 = new Vertex("C")
		
		root.addDependency( rootChild1 )
		rootChild1.addDependency( child1Child1 )
		
		DAG.verify( root )
	}
	
	void testSimpleCyclicDAG() {
		def root = new Vertex("A")
		def rootChild1 = new Vertex("B")
		def child1Child1 = new Vertex("C")
		
		root.addDependency( rootChild1 )
		rootChild1.addDependency( child1Child1 )
		child1Child1.addDependency( root )
		
		try {
			DAG.verify( root )
			fail("CyclicDependencyException expected")
		} catch (CyclicDependencyException e) { /*expected*/ }
	}
}